package com.yvon.maple.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
public class PropertyHelper {

    @Autowired
    private Environment environment;

    /**
     * 获取String类型属性
     *
     * @param key
     * @return
     */
    public String getPropertyString(String key) {
        return environment.getProperty(key);
    }

    /**
     * 获取Integer类型属性
     *
     * @param key
     * @return
     */
    public Integer getPropertyInteger(String key) {
        String value = getPropertyString(key);

        return StringUtils.isBlank(value) ? null : Integer.valueOf(value);
    }

    /**
     * 获取Boolean类型属性
     *
     * @param key
     * @return
     */
    public Boolean getPropertyBoolean(String key) {
        String value = getPropertyString(key);

        return StringUtils.isBlank(value) ? null : Boolean.valueOf(value);
    }
}
